<template>
  <div class="app-container">
    <el-form ref="form" :model="form" label-width="120px">
      <el-form-item label="发件人">
        <el-input v-model="form.ownerName" />
      </el-form-item>

      <el-form-item label="电话">
        <el-input v-model="form.phone" />
      </el-form-item>

      <el-form-item label="内容">
        <el-input v-model="form.content" />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="onSubmit()">提交</el-button>
        <el-button @click="onReset">重置</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
import { addRow } from '@/api/mailbox'
import { validSubmitform } from '@/utils/validate'

export default {
  data() {
    return {
      form: {
        ownerName: '',
        phone: '',
        content: ''
      }
    }
  },
  methods: {
    onReset() {
      this.form = {
        ownerName: '',
        phone: '',
        content: ''
      }
      this.$message({
        message: '已重置',
        type: 'warning'
      })
    },
    onSubmit() {
      console.log('表单数据:', this.form)
      if (validSubmitform(this.form)) {
        addRow(this.form).then(() => {
          this.$message({
            message: '添加成功',
            type: 'success'
          })
        })
      } else {
        this.$message({
          message: '请填写完整信息',
          type: 'warning'
        })
      }
    }
  }
}
</script>

<style scoped>
.line{
  text-align: center;
}
</style>
